#include <iostream>
#include "ros/ros.h"

#include "demo_msg/Student.h"
#include "demo_msg/Team.h"

using namespace std;

int main(int argc, char **argv) {
  // 创建节点
  string nodeName = "my_publisher1";
  ros::init(argc, argv, nodeName);
  ros::NodeHandle node;

  //通过节点创建发布者
  string topicName = "my_topic";
  const ros::Publisher &publisher = node.advertise<demo_msg::Team>(topicName, 1000);

  int index = 0;
  ros::Rate rate(1);
  while (ros::ok()) {
    //通过publisher发布消息
    // demo_msg::Student stu_msg;
    // stu_msg.name = "name-" + to_string(index);
    // stu_msg.age = index;
    // publisher.publish(stu_msg);

    //通过publisher发布消息
    demo_msg::Team team_msg;
    team_msg.name = "team_msg name-" + to_string(index);
    team_msg.leader.name = "team_msg leader name-" + to_string(index);
    team_msg.leader.age = index;
    team_msg.intro.data = "intro-" + to_string(index);

    team_msg.location.linear.x = index + 1;
    team_msg.location.linear.y = index + 2;
    team_msg.location.linear.z = index + 3;
    team_msg.location.angular.x = index + 4;
    team_msg.location.angular.y = index + 5;
    team_msg.location.angular.z = index + 6;

    for (int i = 0; i < 3; ++i) {
      demo_msg::Student stu;
      stu.name = "stu-" + to_string(index) + "-"+ to_string(i);
      stu.age = i;
      team_msg.members.push_back(stu);
    }

    publisher.publish(team_msg);

    index++;
    rate.sleep();
  }

  ros::spin();
  return 0;
}